#include <QHBoxLayout>

#include <messaginglayer/contactsmodel.h>

#include "contactlistview.h"
#include "contactswidget.h"
#include "icore.h"
#include "mainwindow.h"

ContactsWidget::ContactsWidget(QWidget *parent) :
    QWidget(parent),
    m_contactsView(new ContactListView(this))
{
    QHBoxLayout * l = new QHBoxLayout(this);
    l->setContentsMargins(0, 0, 0, 0);

    l->addSpacerItem(new QSpacerItem(10, 15, QSizePolicy::Minimum, QSizePolicy::Expanding));
    l->addWidget(m_contactsView);
    l->addSpacerItem(new QSpacerItem(10, 15, QSizePolicy::Minimum, QSizePolicy::Expanding));

    m_contactsView->setFixedWidth(450);
    m_contactsView->setFrameStyle(QFrame::NoFrame);
    connect(m_contactsView, SIGNAL(messagingRequest(ContactInfo)),
            ICore::instance()->mainWindow(), SLOT(openMessaging(ContactInfo)));
}

ContactsModel * ContactsWidget::contactsModel() const
{
    return qobject_cast<ContactsModel *>(m_contactsView->model());
}

void ContactsWidget::setContactsModel(ContactsModel *model)
{
    m_contactsView->setModel(model);
}
